package com.ttt.gdfood.mapper;

import com.ttt.gdfood.entity.Collection;
import com.ttt.gdfood.entity.ThumbsUp;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Mapper
public interface ThumbsUpMapper {
    // 获取笔记被点赞的用户id
    @Select("SELECT uid FROM thumbsup WHERE tn_id=#{tn_id}")
    @Transactional
    List<ThumbsUp> getUid(int tn_id);

    //  获取用户关注数
    @Select("SELECT count(tn_id) FROM thumbsup WHERE uid=#{uid}")
    @Transactional
    int getThumbsNum(int uid);

    // 用户点赞笔记
    @Insert("INSERT into thumbsup (`uid`, `tn_id`) VALUES (#{uid},#{tn_id})")
    @Transactional
    void insertThumbsup(int uid,int tn_id);

    // 根据用户收藏的笔记id删除
    @Delete("DELETE FROM thumbsup WHERE tn_id=#{tn_id}")
    void delThumbsupByTnid(int tn_id);
}
